﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SyncLib.Client;
using Microsoft.Synchronization;

namespace SyncApplication.Business
{
   public class GridMonitorEvent:MonitorEvent
    {
       public string ScopeName
       {
           get
           {
               if (ClientSyncContext.CurrentTask != null
                   && ClientSyncContext.CurrentTask.RowState != System.Data.DataRowState.Deleted
                   && ClientSyncContext.CurrentTask.RowState != System.Data.DataRowState.Detached)
                   return ClientSyncContext.CurrentTask.ScopeName;
               else
                   return "Unknown";
           }
       }
        public override void RaiseEvent(SyncEventType type, string icon, string message)
        {
            InvokeSetStatus(message);
        }

        public override void RaiseCommunicationEvent(SyncEventType type, string icon, string message)
        {
            InvokeSetStatus(message);
        }

        public override void SyncStateChange(SyncOrchestratorState state, string message)
        {
            InvokeSetStatus(message);
        }

        public override void Info(string message)
        {
            InvokeSetStatus(message);
        }
        void InvokeSetMessage(string msg)
        {
            if (ClientSyncContext.CurrentTask != null)
                ClientSyncContext.CurrentTask.Message = msg;
            return;
            //SyncDialog.Current.GridMain.Invoke(new MethodInvoker(delegate
            //{
            //    ClientSyncContext.CurrentTask.Message = msg;
            //}));
           // SyncDialog.Current.SetMessage(ScopeName, msg);
        }
        void InvokeSetStatus(string msg)
        {
            //SyncDialog.Current.GridMain.Invoke(new MethodInvoker(delegate
            //{
            //    ClientSyncContext.CurrentTask.Status = msg;
            //}));
            if (ClientSyncContext.CurrentTask != null)
                ClientSyncContext.CurrentTask.Status = msg;
            return;
           // SyncDialog.Current.SetStatus(ScopeName, msg);
        }
       
    }
}
